﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;

public partial class Admin_ImgNewsEdit : System.Web.UI.Page
{
    public string indID;
    protected void Page_Load(object sender, EventArgs e)
    {
        indID = Request.QueryString["id"];        
        tbPicturePath.Attributes.Add("ReadOnly", "true");
        if (!IsPostBack)
        {
            DataTable dt;
            string c="";
            ListItem li = new ListItem("阿城警事", "1");
            DropDownList1.Items.Add(li);
            li = new ListItem("图片新闻", "2");
            DropDownList1.Items.Add(li);
            if (!string.IsNullOrEmpty(indID))
            {
                ImgNewsData ind = new ImgNewsData();
                ind.ID = new Guid(indID);
                dt = ImgNewsDataDBOption.DataTableSelect(ind);
                DataRow dr = dt.Rows[0];
                c = dr["Category"].ToString();
                TextBox1.Text = dr["Title"].ToString();
                CheckBox1.Checked = Convert.ToBoolean(dr["Top"]);
                Insert_WebEditor.Text = dr["Txt"].ToString();
                tbPicturePath.Text = dr["Img"].ToString();
                if(c=="1")
                    DropDownList1.SelectedIndex = 0;
                else
                    DropDownList1.SelectedIndex = 1;
            }           
            
        }
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ImgNewsData ind = new ImgNewsData();
        ind.Category = DropDownList1.SelectedValue;
        ind.EditDate = DateTime.Now;
        ind.Title = TextBox1.Text;
        ind.Img = tbPicturePath.Text;
        ind.Top = CheckBox1.Checked;
        ind.Txt = Insert_WebEditor.Text;
        if (string.IsNullOrEmpty(indID))
            ImgNewsDataDBOption.Insert(ind);
        else
        {
            ind.ID = new Guid(indID);
            ImgNewsDataDBOption.Update(ind);
        }
        Response.Redirect("~/Admin/ImgNewsList.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("~/login.aspx");
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("~/login.aspx");
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/SearchList.aspx?search=" + Server.UrlEncode(TextBox2.Text));
    }
}